package com.foxmail.aroundme.boring.utils.util;

import android.content.Context;

import com.bumptech.glide.DrawableRequestBuilder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.foxmail.aroundme.boring.BuildConfig;
import com.foxmail.aroundme.boring.R;
import com.foxmail.aroundme.boring.utils.Config;
import com.socks.library.KLog;

/**
 * Created by gzl on 2/1/17.
 *
 * 主要是做成一个单例模式，保证只加载一个实例
 */

public class GlideGifUtils {

    private static volatile GlideGifUtils glideGifUtils;

    private RequestManager requestManager;

    private GlideGifUtils(Context context){
        requestManager = Glide.with(context);
    }

    public static GlideGifUtils newsInstance(Context context) {
        if (glideGifUtils == null) {
            synchronized (GlideGifUtils.class) {
                if (glideGifUtils == null) {
                    glideGifUtils = new GlideGifUtils(context);
                }
            }
        }
        return glideGifUtils;
    }

    public DrawableRequestBuilder loadGif(String url) {
        if (requestManager == null) {
            return null;
        }

        return requestManager.load(url)
                .thumbnail(1f)
                .error(R.drawable.icon_picture_error)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .crossFade()
                .fitCenter()
                .skipMemoryCache(true);
    }

}
